<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head th:replace="common/header :: common_head(~{::title},~{},~{::link})">
    <title th:text="'修改密码_'+#{website.name}"></title>
    <link rel="stylesheet" href="/css/user.css"/>
</head>
<body class="">

<div th:replace="common/top :: top('')">
</div>
<div class="main box_center cf">
    <div class="userBox cf">
        <div class="my_l">

            <ul class="log_list">
                <li><a class="link_1 " href="/user/userinfo.html">个人中心</a></li>
                <li><a class="link_4" href="/user/favorites.html">我的书架</a></li>
                <li><a class="link_6" href="/user/comment.html">我的书评</a></li>
                <li><a class="link_7 " href="/user/feedback_list.html">我的反馈</a></li>
                <li><a class="link_8 on" href="/user/setup.html">账号设置</a></li>
            </ul>

        </div>
        <div class="my_r">
            <div class="my_info cf">
                <div class="my_info_txt">
                        <div class="aspNetHidden">
                            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5NTM3Mjc0MTkPZBYEZg9kFgJmDxYCHgRUZXh0BagBPGEgaHJlZj0iL3NlYXJjaC5hc3B4P3NlYXJjaEtleT3llrvlronpm6/vvIzni4Tms73vvIzngbXlvILvvIzliY3kuJbku4rnlJ/vvIzlhqXnjovprLzlpKsiIHRhcmdldD0iX2JsYW5rIj7llrvlronpm6/vvIzni4Tms73vvIzngbXlvILvvIzliY3kuJbku4rnlJ/vvIzlhqXnjovprLzlpKs8L2E+ZAICD2QWAgIJDw8WAh8ABSHkuKTmrKHovpPlhaXnmoTmlrDlr4bnoIHkuI3ljLnphY1kZGRhp36YOW0VXvnzag3X7ggb4GZjGR2iOhc3esYV+gLQoA==" />
                        </div>

                        <div class="aspNetHidden">

                            <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="65B8FACB" />
                            <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAX/+YBS+s4SAkXd5M3/Ah/txr1QWsMVpxihbk+u9oMvC/bi8V6FV2PI0iftNhvgoqk7nMhcHLH9bj8jEonVtSua9n7/EOPGKgFySK9U6TwmXfgmt+UwsLWDkQL9tHgrPR3yuBzIgg7/7BXfGNHKEmhv" />
                        </div>
                        <ul class="mytab_list">
                            <li><i class="tit">我的密码</i><input name="oldPass" type="password" id="txtOldPass" class="s_input" placeholder="请输入原密码" /></li>
                            <li><i class="tit">&nbsp;</i><input name="txtNewPass1" type="password" id="txtNewPass1" class="s_input" placeholder="请输入新密码" /></li>
                            <li><i class="tit">&nbsp;</i><input name="txtNewPass2" type="password" id="txtNewPass2" class="s_input" placeholder="请确认新密码" /></li>
                            <li><i class="tit">&nbsp;</i><input type="submit" name="btnExchangePassword" value="修改" id="btnExchangePassword" onclick="updatePassword()" class="s_btn btn_red" /></li>
                            <li><i class="tit">&nbsp;</i><span id="LabErr"></span></li>
                        </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div th:replace="common/footer :: footer">
</div>
<div th:replace="common/js :: js"></div>
<script type="text/javascript">
    function updatePassword() {
        var oldPassword = $("#txtOldPass").val();
        if (oldPassword.isBlank()) {
            $("#LabErr").html("旧密码不能为空！");
            return;
        }
        var newPassword1 = $("#txtNewPass1").val();
        if (newPassword1.isBlank()) {
            $("#LabErr").html("新密码不能为空！");
            return;
        }
        var newPassword2 = $("#txtNewPass2").val();
        if (newPassword2.isBlank()) {
            $("#LabErr").html("确认密码不能为空！");
            return;
        }
        if(newPassword1 !== newPassword2){
            $("#LabErr").html("两次输入的新密码不匹配！");
            return;
        }
        $.ajax({
            type: "POST",
            url: "/user/updatePassword",
            data: {'oldPassword':oldPassword,'newPassword1':newPassword1,'newPassword2':newPassword2},
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    window.location.href = '/user/setup.html';

                } else if (data.code == 1001) {
                    //未登录
                    location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                } else {
                    $("#LabErr").html(data.msg);
                }

            },
            error: function () {
                layer.alert('网络异常');
            }
        })
    }
</script>

</body>
</html>
